package com.ysd.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.ProductDaoImpl;
import com.ysd.dao.impl.ProductcategoryDaoImpl;
import com.ysd.entity.Product;
import com.ysd.entity.Productcategory;

public class ProductsServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 调用实现类
		// 产品分类
		ProductcategoryDaoImpl productcategoryDao = new ProductcategoryDaoImpl();
		List<Productcategory> productcategoryList = productcategoryDao.getProductcategory();
		request.setAttribute("productcategoryList", productcategoryList);
		
		// 根据产品分类id查询对应的产品
		// 接收前台传来的参数
		int cId = Integer.parseInt(request.getParameter("CategoryId"));
		ProductDaoImpl pDao = new ProductDaoImpl();
		List<Product> productList = pDao.getProduct(cId);
		request.setAttribute("productList", productList);
		
		// 调用产品分类实现类中产品系列id查询制定id的数据
		int pId = Integer.parseInt(request.getParameter("CategoryId"));
		ProductcategoryDaoImpl xiLieDao = new ProductcategoryDaoImpl();
		List<Productcategory> xiLieList = xiLieDao.getProductcategoryList(pId);
		request.setAttribute("xiLieList", xiLieList);
		
		request.getRequestDispatcher("productlist.jsp").forward(request, response);//转发
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
